import {Resolve, ActivatedRouteSnapshot, RouterStateSnapshot, Router} from "@angular/router";
import {Product} from "../product/product.component";
import {Injectable} from "@angular/core";

@Injectable()
export class ProductResolve implements Resolve<Product>{
  constructor(private route:Router){}
  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot){
    //获取对应传递的id
    let id:number = route.params['id'];
    if(id == 1){
      return new Product(1,'xiaomi');
    }else{
      this.route.navigate(['/home']);
      return undefined;
    }
  }
}
